package com.ridanlabs.professorwebsite.models;

import java.util.HashSet;

import javax.persistence.Id;
import javax.persistence.PostLoad;

import com.google.appengine.api.blobstore.BlobKey;
import com.googlecode.objectify.Key;
import com.ridanlabs.professorwebsite.general.CourseSeason;

public class Course {
	@Id private String id;
	private String courseName;
	private String section;
	private CourseSeason season;
	private Key<UserProfile> courseProfessor;
	private HashSet<Key<UserProfile>> courseStudents; 
	private HashSet<BlobKey> notes;
	
	public Course() {
		this.courseStudents = new HashSet<Key<UserProfile>>();
		this.notes = new HashSet<BlobKey>();
	}
	
	/*
	 * Setter/getter methods.
	 */
	public String getId() { return this.id; }
	public void setId( String id ) { this.id = id; }
	
	public String getCourseName() { return this.courseName; }
	public void setCourseName( String courseName ) { this.courseName = courseName; }
	
	public String getSection() { return this.section; }
	public void setSection( String section ) { this.section = section; }
	
	public CourseSeason getSeason() { return this.season; }
	public void setSeason( CourseSeason season ) { this.season = season; }
	
	public Key<UserProfile> getCourseProfessor() { return this.courseProfessor; }
	public void setCourseProfessor( Key<UserProfile> courseProfessor ) { this.courseProfessor = courseProfessor; }
	
	public HashSet<Key<UserProfile>> getCourseStudents() { return this.courseStudents; }
	public void setCourseStudents( HashSet<Key<UserProfile>> courseStudents ) { this.courseStudents = courseStudents; }
	
	public HashSet<BlobKey> getNotes() { return this.notes; }
	public void setNotes( HashSet<BlobKey> notes) { this.notes = notes;}
	
	/*
	 * Helper methods.
	 */
	public Key<Course> getKey() {
		return new Key<Course>(Course.class, this.id);
	}
	
	public boolean insertNotesFile( BlobKey notesFile ) {
		return this.notes.add(notesFile);
	}
	
	public boolean addStudent( Key<UserProfile> studentKey ) {
		return this.courseStudents.add(studentKey);
	}
	
	/*
	 * Save/load processing.
	 */
	@SuppressWarnings("unused")
	@PostLoad //function called before loaded for consumption
	private void processOnLoad() {
		if( courseStudents == null ) 
			courseStudents = new HashSet<Key<UserProfile>>();
			
		if( notes == null )
			notes = new HashSet<BlobKey>();
	}
}
